<?php
require_once('functions/config.php');
function login( $login, $password ) {
  $login = mysql_real_escape_string( trim( $login ) );
  $password = mysql_real_escape_string( trim( $password ) );
  if( $password != "" AND $login != "" )
  {
    $password = sha1($password);
    $select_id = mysql_query("SELECT id FROM accounts WHERE login='$login' AND password='$password'");
    $check = mysql_num_rows($select_id);
    $temp = mysql_fetch_array($select_id);
    $id = $temp['id'];
    if( $check == 1 )
    {
      $_SESSION['user_id'] = $id;
      $_SESSION['login'] = $konto;
      echo 'Zalogowano na konto '. $konto;
    }
    else
    {
      echo 'Zle dane, Sproboj ponownie.';
    }
  }
  else
  {
    echo 'Wpisz wszystkie dane.';
  }
}
  $mysql_connect = mysql_connect( DB_CORE_ADDRESS, DB_CORE_USERNAME, DB_CORE_PASSWORD );
  $mysql_select_db = mysql_select_db( DB_CORE_DATABASE );
  $mysql_query = mysql_query("SELECT * FROM players WHERE id=1") or die('Błąd zapytania'); 
  session_start();
  if (isset($_POST['konto']) and isset($_POST['password']) )
  {
    login( $_POST['konto'], $_POST['password'] );
  }
  else
  {
  ?>
    <form  action="login.php" method="post">
      <strong>Nazwa konta:</strong><input name="konto" type="text" value="" /><br>
      <strong>Haslo:</strong><input name="password" type="password" value="" /><br>
      <input type="submit" value="Zaloguj" />
    </form>
<?php
  }
?>

